# Maintainer: Diego Sogari <diego.sogari@falker.com.br>

_realname=nanodbc
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.12.4
pkgrel=2
pkgdesc="A small C++ wrapper for the native C ODBC API (mingw-w64)"
arch=('any')
url="http://nanodbc.io/"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
source=("${_realname}-${pkgver}.tar.gz"::https://github.com/nanodbc/nanodbc/archive/v${pkgver}.tar.gz
        "${_realname}-${pkgver}.patch")
sha256sums=('ad2b6275ceb172a2fa9cbf53c5ea8fdda7257a61b2aff572a673f47d0040a2d8'
            '289c87a689867a105224b2cfe0e74d54019ff02de7599c13b959a380f02846b7')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"
  patch -Np1 -i "../${_realname}-${pkgver}.patch"
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake.exe \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    -DNANODBC_TEST=OFF \
    "../${_realname}-${pkgver}"

  make
}

#check() {
#  Note: to run the tests it would be necessary to have installed at least the
#  SQLite ODBC drivers for both 32- and 64-bit. In our local Windows machine,
#  all tests passed. The drivers used were:
#    - SQLite3 ODBC Driver 32-bit (version 0.9993.00.00)
#    - SQLite3 ODBC Driver 64-bit (version 0.9993.00.00)
#    - MySQL ODBC 5.3 ANSI Driver 32-bit (version 5.03.04.00)
#    - MySQL ODBC 5.3 ANSI Driver 64-bit (version 5.03.04.00)
#    - MySQL ODBC 5.3 Unicode Driver 32-bit (version 5.03.04.00)
#    - MySQL ODBC 5.3 Unicode Driver 64-bit (version 5.03.04.00)
#
#  cd "${srcdir}/build-${MINGW_CHOST}"
#  export NANODBC_TEST_CONNSTR=`cat ../../connection_string.txt`
#  SAVED_PATH=${PATH}
#  PATH=`pwd`:${PATH}
#  make test
#  PATH=${SAVED_PATH}
#}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
